package com.young.rabbitmq.ack;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.young.rabbitmq.util.ConnectionUtil;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeoutException;

/**
 * 生产者，发送消息，测试消费者端手动ack
 */
public class Producer {
    static final String QUEUE_NAME = "work_queue";

    public static void main(String[] args) throws IOException, TimeoutException {
        //5、建立连接
        Connection connection = ConnectionUtil.buildConnection();
        //6、创建通道,一个连接中可以包含多个通道
        Channel channel = connection.createChannel();
        //7、声明/创建队列
        channel.queueDeclare(QUEUE_NAME, true, false, false, null);
        channel.basicPublish("", QUEUE_NAME, null, ("hello rabbit MQ").getBytes(StandardCharsets.UTF_8));

        // 9、关闭资源
        channel.close();
        connection.close();
    }
}
